<?php
namespace app\common\controller;
use think\Controller;

use AlibabaCloud\SDK\Facebody\V20191230\Facebody;
use \Exception;
use AlibabaCloud\Tea\Exception\TeaError;
use AlibabaCloud\Tea\Utils\Utils;

use Darabonba\OpenApi\Models\Config;
use AlibabaCloud\SDK\Facebody\V20191230\Models\CompareFaceRequest;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;

class AliFacebody extends Controller
{
    /**
     * 使用AK&SK初始化账号Client
     * @param string $accessKeyId
     * @param string $accessKeySecret
     * @return Facebody Client
     */
    public function createClient($accessKeyId, $accessKeySecret){
        $config = new Config([
            // 必填，您的 AccessKey ID
            "accessKeyId" => $accessKeyId,
            // 必填，您的 AccessKey Secret
            "accessKeySecret" => $accessKeySecret
        ]);
        // Endpoint 请参考 https://api.aliyun.com/product/facebody
        $config->endpoint = "facebody.cn-shanghai.aliyuncs.com";
        return new Facebody($config);
    }

    /**
     * @param string[] $args
     * @return void
     */
    public function photoVerifyPhoto($imgA,$imgB){

        $config = \config('aliyun_sms'); //获取配置信息
        $accessKeyId = $config['KeyID'];//阿里云短信keyId
        $accessKeySecret = $config['KeySecret'];//阿里云短信keysecret

        $client = $this->createClient($accessKeyId, $accessKeySecret);
        $compareFaceRequest = new CompareFaceRequest([
            "imageDataA" => $imgA,
            "imageDataB" => $imgB
        ]);
        $runtime = new RuntimeOptions([]);
        try {
            // 复制代码运行请自行打印 API 的返回值
            return $client->compareFaceWithOptions($compareFaceRequest, $runtime);
        }
        catch (Exception $error) {
            if (!($error instanceof TeaError)) {
                $error = new TeaError([], $error->getMessage(), $error->getCode(), $error);
            }
            // 如有需要，请打印 error
            return Utils::assertAsString($error->message);
        }
    }


}